

goods = [(60,10),(100,20),(120,30)] # 每个商品元组表示（价格，重量）


def fractional_backpack(goods,w):
    goods.sort(key = lambda x: x[0]/x[1], reverse = True) #降序
    m = [0 for _ in range(len(goods))]
    total_v = 0
    for i, (prize, weight) in enumerate(goods):
        if w >= weight:
            m[i] = 1
            w -= weight
            total_v += prize
        else:
            m[i] = w/weight
            total_v += m[i] * prize
            w = 0
            break
    return total_v,m



print(fractional_backpack(goods,50))